import {
	Body,
	Controller,
	Get,
	HttpStatus,
	Post,
	Query,
	Req,
	Res,
} from "@nestjs/common";
import { WechatService } from "./wechat.service";
import { ValidationDto } from "./dto/validation.dto";
import { Public } from "@/common/decorators/public.decorator";
import { Response } from "express";
import { BatchSendDto } from "./dto/batch-send.dto";

@Controller("wechat")
export class WechatController {
	constructor(private readonly wechatService: WechatService) {}

	@Public()
	@Get("valid")
	async checkSignature(@Query() queryObj: ValidationDto, @Res() res: Response) {
		console.log("打印***obj", queryObj);
		const result = await this.wechatService.checkSignature(queryObj);
		res.header("Content-Type", "text/plain");
		res.status(HttpStatus.OK).send(result);
	}

	@Public()
	@Get("wxLogin")
	async wxLogin(@Query("code") code: string) {
		return await this.wechatService.wxLogin(code);
	}

	@Post("sendMsg")
	async batchSendMsg(@Body() body: BatchSendDto) {
		return await this.wechatService.batchSendMsg(body.openidList);
	}
}
